<?php

namespace app\controller\v1;

use app\model\LineModel;
use app\validate\LineValidate;

class Line extends System
{
    /**
     * Notes: 分页
     * User: chenLei
     * Date: 10/13/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function list()
    {
        $lineModel = new LineModel();
        $res = $lineModel->list($this->params);
        return $this->successJson('ok', $res);
    }
    /**
     * Notes: 全部
     * User: chenLei
     * Date: 10/13/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function all()
    {
        $lineModel = new LineModel();
        $res = $lineModel->all($this->params);
        return $this->successJson('ok', $res);
    }

    /**
     * Notes: 添加
     * User: chenLei
     * Date: 10/13/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function add()
    {
        $validate = new LineValidate();
        if (!$validate->scene('add')->check($this->params)) return $this->errorJson($validate->getError());

        $lineModel = new LineModel();
        $res = $lineModel->add($this->params);
        if ($res === false) return $this->errorJson($lineModel->getError());
        return $this->successJson('ok');
    }

    /**
     * Notes: 编辑
     * User: chenLei
     * Date: 10/13/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function edit()
    {
        $validate = new LineValidate();
        if (!$validate->scene('edit')->check($this->params)) return $this->errorJson($validate->getError());

        $lineModel = new LineModel();
        $res = $lineModel->edit($this->params);
        if ($res === false) return $this->errorJson($lineModel->getError());
        return $this->successJson('ok');
    }

    /**
     * Notes: 删除
     * User: chenLei
     * Date: 10/13/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */

    public function del()
    {
        $validate = new LineValidate();
        if (!$validate->scene('del')->check($this->params)) return $this->errorJson($validate->getError());

        $lineModel = new LineModel();
        $res = $lineModel->del($this->params);
        if ($res === false) return $this->errorJson($lineModel->getError());
        return $this->successJson('ok');
    }
}